perm filename PROB7.PUB[LSP,JRA]9 blob
sn#255926 filedate 1976-12-29 generic text, type C, neo UTF8
COMMENT ⊗ VALID 00002 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 .GROUP
C00005 ENDMK
C⊗;
.GROUP
.CENT(Problems involving %3prog%*)
.BEGIN SELECT 1;INDENT 0,17;
I. Write %3prog%*-versions of the following functions (or predicates).
%21.%3 member <= λ[[x;y] ...]%1:%3 x%1 is atomic; %3y%* is a list of atoms. %3member%* is to
return %et%* just in the case that %3x%* is one of the elements in %3y%*.
.end
.APART
.BEGIN SELECT 1;INDENT 0,15;
.GROUP;
%22.%1 The factorial function.
%23.%3 delete <= λ[[x;y] ... ]%1: %3x%1 is atomic; %3y%* is a list of atoms. %3delete%* is to
return a list which looks like %3y%*, except all occurrences of %3x%*
have been deleted.
%24.%1 The %3append%* function.
.APART
.GROUP;
%25.%3 last <= λ[[x] ...]%1: %3x%1 is a non-empty list. %3last%* is to return the last
element in %3x%*.
%26.%1 Now write the S-expr translations of each of your functions.
II. What is necessary to extend the evaluator to recognize %3prog%* and friends?
.END
.BEGIN INDENT 0,4;GROUP;
III. The %3go[cdr[...]]%*-construct on {yon(P25)} is better handled with a %2⊗→case
statement↔←%*. A typical syntax for such might be:
.P70:
←case<index>of <form%41%*>; ... ;<form%4n%*>.
<index> is to evaluate to an integer, i. Where 0<i≤n. The i%8th%* <form> of the
case-statement is executed, and is the value of the statement.
Give a representation for the case statement and extend the evaluator to recognize
it.
.apart
.group
IV. Some languages allow
constructs like:
.BEGIN TURN OFF "←";CENTER;
(%2if%* p(x) %2then%* x %2else%* y) ← exp, which is to mean the same as:
%2if%* p(x) %2then%* x← exp %2else%* y ← exp
.END
Can such a construct be written in LISP?
.apart
V. Compare the %3prog%* version of %3length%* on {yon(P45)} with
%3length%41%1 on {yon(P19)}. Do you see any interesting relationships?
.END